package com.personal.test.common.domin;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import lombok.Data;

import java.util.Date;

/**
 * @author linyh
 * @version 1.0
 * @email 1503386669@qq.com
 * @date 2020/10/23 11:54
 */
@Data
public class BaseEntity {
    // 主键自增 数据库中需要设置主键自增
    @TableId(type = IdType.UUID)
    private String id;
    private Date createDate;
    private String createBy;
    private Date updateDate;
    private String updateBy;
    @TableLogic
    private String delFlag;

    /**
     * 数据插入之前做相关操作
     */
    public void preSet(){
        if(null == createBy){
            createBy = "1";
        }
        if(null == createDate){
            createDate = new Date();
        }
        if(null == updateBy){
            updateBy = "1";
        }
        if(null == updateDate){
            updateDate = new Date();
        }
        if(null == delFlag){
            delFlag = "0";
        }
    }

    /**
     * 数据更新之前做相关操作
     */
    public void preUpdate(){
        if(null == updateBy){
            updateBy = "1";
        }
        if(null == updateDate){
            updateDate = new Date();
        }
    }

}
